import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 待保养模具信息 */
export interface UpkeepTobe {
  id: number // 主键
  accountId?: number // 模具台账id
  drawingNoId?: number // 图号id
  upkeepId: number // 保养类型id
  ifTmp: number // 是否临时保养
  status: number // 任务状态
  taskId: number // 任务id
  itemId?: number // 保养项目主键
}

/**  派工接口信息 */
export interface UpkeepTobeDispatch {
  id: number // 主键
  assigneerId: number // 保养人ID
}

// 待保养模具 API
export const UpkeepTobeApi = {
  // 查询待保养模具分页
  getUpkeepTobePage: async (params: any) => {
    return await request.get({ url: `/mold/upkeep-tobe/page`, params })
  },

  // 查询待保养模具详情
  getUpkeepTobe: async (id: number) => {
    return await request.get({ url: `/mold/upkeep-tobe/get?id=` + id })
  },

  // 新增待保养模具
  createUpkeepTobe: async (data: UpkeepTobe) => {
    return await request.post({ url: `/mold/upkeep-tobe/create`, data })
  },

  // 修改待保养模具
  updateUpkeepTobe: async (data: UpkeepTobe) => {
    return await request.put({ url: `/mold/upkeep-tobe/update`, data })
  },

  // 删除待保养模具
  deleteUpkeepTobe: async (id: number) => {
    return await request.delete({ url: `/mold/upkeep-tobe/delete?id=` + id })
  },

  /** 批量删除待保养模具 */
  deleteUpkeepTobeList: async (ids: number[]) => {
    return await request.delete({ url: `/mold/upkeep-tobe/delete-list?ids=${ids.join(',')}` })
  },

  // 导出待保养模具 Excel
  exportUpkeepTobe: async (params) => {
    return await request.download({ url: `/mold/upkeep-tobe/export-excel`, params })
  },

  // 派工接口
  dispatchUpkeepTobe: async (id: number, assigneerId: number) => {
    return await request.put({
      url: `/mold/upkeep-tobe/dispatch`,
      data: { id, assigneerId }
    })
  },

  // 撤销接口
  cancelDispatchUpkeepTobe: async (id: number) => {
    return await request.put({ url: `/mold/upkeep-tobe/cancel-dispatch?id=${id}` })
  },

  // 审核接口
  auditUpkeepTobe: async (data: any) => {
    return await request.put({
      url: `/mold/upkeep-tobe/audit`,
      data
    })
  }
}
